package com.powernode.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.SysLog;
import com.powernode.model.Result;
import com.powernode.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统日志控制层
 */
@Api(tags = "系统日志接口管理")
@RequestMapping("sys/log")
@RestController
public class SysLogController {
    @Autowired
    private SysLogService sysLogService;

    @ApiOperation("多条件分页查询系统操作日志")
    @GetMapping("page")
    public Result<Page<SysLog>> loadSysLogPage(Page<SysLog> page,SysLog sysLog) {
        page = sysLogService.page(page,new LambdaQueryWrapper<SysLog>()
                // 当前查询条件eq和like同时存在时，应该优先写eq查询条件
                .eq(ObjectUtil.isNotNull(sysLog.getUserId()),SysLog::getUserId,sysLog.getUserId())
                .like(StringUtils.hasText(sysLog.getOperation()),SysLog::getOperation,sysLog.getOperation())
                .orderByDesc(SysLog::getCreateDate)
        );
        return Result.success(page);
    }
}
